package translinkApp.Adaptors;

import translinkApp.Activities.R;
import translinkApp.Data.Journey.Search.JourneySearch;
import translinkApp.Data.Journey.Search.JourneySearchList;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class HistoryArrayAdapter extends ArrayAdapter {

	private Context context;

	public HistoryArrayAdapter(Context context, JourneySearchList list) {
		super(context, R.layout.historylistitem, list);

		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		JourneySearch c = (JourneySearch) getItem(position);

		// if the array item is null, nothing to display, just return null
		if (c == null) {
			return null;
		}

		// Pick up the TwoLineListItem defined in the xml file
		View view = View.inflate(context, R.layout.historylistitem, null);

		TextView fromLocation = (TextView) view.findViewById(R.id.historyFromLoc);
		fromLocation.setText(c.getFromLocation().getDisplayAddress());

		TextView toLocation = (TextView) view.findViewById(R.id.historyToLoc);
		toLocation.setText(c.getToLocation().getDisplayAddress());

		TextView dateTime = (TextView) view.findViewById(R.id.historyDateTime);
		dateTime.setText(c.getTime().toString() + " " + c.getDate().toDisplayString());

		return view;
	}

}